<template>
<view>
<block v-if="now_status==1">
	<view class="qp_img_box">
    <image mode="aspectFill" :src="webUrl + 'addons/monai_market/static/wimgs/jsz_img.png'"></image>
  </view>
</block>

<block v-if="now_status==0">
	<view class="send_butt" @tap="click_send">{{st_word}}</view>
	<block v-for="(item, index) in listInfo" :key="index">
		<view class="ju_cont_box">
			<view class="cont_item1">{{item.title}}</view>
			<view class="cont_item">联系人：{{item.name}}</view>
			<view class="cont_item">联系电话：{{item.tel}}</view>
			<view class="clear"></view>
			<view class="cont_item2">
				<view class="ci_item">{{item.address!=null&&item.address!=''?item.address:''}}</view>
				<view class="ci_item">发布时间：{{item.createtime}}</view>·
			</view>
			<block v-if="wh==1||wh==2">
				<button class="det_butt" :data-id="item.id" @tap="click_toDet">职位详情</button>
			</block>
			<block v-if="wh==3||wh==4">
				<view class="butt_lab_box">
					<label class="dele" :data-id="item.id" :data-index="index" @tap="deleteZp">删除</label>
					<label :data-id="item.id" @tap="click_update">编辑</label>
					<label class="det_lab" :data-id="item.id" @tap="click_toDet">查看详情</label>
				</view>
			</block>
		</view>
	</block>
	<block v-if="listInfo.length==0">
		<view class="tips_box">暂时还没有信息哟~</view>
	</block>
</block>
</view>
</template>

<script>
var app = getApp(),
    upurl = app.globalData.util.url("entry/wxapp/Api", {
  m: "monai_market",
  uid: wx.getStorageSync("uid"),
  r: "Upimg"
});

export default {
  data() {
    return {
      wh: '',
      leftid: 1,
      listInfo: [],
      st_word: '',
      webUrl: '',
      now_status: 1
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.check_st();
    that.setData({
      wh: options.wh
    });
    that.check_status();
    app.globalData.imgUrl();
    setTimeout(() => {
      that.setData({
        webUrl: wx.getStorageSync('webUrl')
      });
    }, 500);

    if (options.wh == 1) {
      wx.setNavigationBarTitle({
        title: '找工作'
      }), that.getWRlist();
    } else if (options.wh == 2) {
      wx.setNavigationBarTitle({
        title: '租赁'
      }), that.getWRlist();
    } else if (options.wh == 3) {
      wx.setNavigationBarTitle({
        title: '我的招聘'
      }), that.getUserList();
    } else {
      wx.setNavigationBarTitle({
        title: '我的租赁'
      }), that.getUserList();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.wh == 1 || that.wh == 2) {
      that.getWRlist();
    } else {
      that.getUserList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    check_status: function () {
      var that = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "home.index.examine"
        },
        success: function (res) {
          console.log('状态', res.data);
          that.setData({
            now_status: res.data.data
          });
        },
        fail: function (res) {}
      });
    },
    check_st: function () {
      var that = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "home.index.change_word",
          m: "monai_market"
        },
        cachetime: "0",
        success: function (res) {
          console.log('abc:', res.data);
          var json = res.data.data;
          wx.setNavigationBarTitle({
            title: res.data.data
          });
          that.setData({
            st_word: res.data.data
          });
        }
      });
    },
    //点击编辑按钮
    click_update: function (e) {
      var taht = this;
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pagesA/sJobLease/sJobLease?tid=2&id=' + id
      });
    },
    //删除招聘或租赁信息
    deleteZp: function (e) {
      var that = this;
      var id = e.currentTarget.dataset.id,
          index = e.currentTarget.dataset.index;
      wx.showModal({
        title: '提示',
        content: '是否确定删除此条信息？',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            console.log('确定');
            app.globalData.util.request({
              url: "entry/wxapp/Api",
              data: {
                r: "home.index.userdel_workrent",
                m: "monai_market",
                uid: app.globalData.getuid(),
                id: id
              },
              cachetime: "0",
              success: function (a) {
                console.log('删除返回：', a.data);
                var arr = that.listInfo;
                arr.splice(index, 1);
                that.setData({
                  listInfo: arr
                });
              }
            });
          } else {
            console.log('取消');
          }
        }
      });
    },
    //获取用户自己发布的租赁或招聘信息
    getUserList: function () {
      var that = this;
      var type = 1;

      if (that.wh == 4) {
        type = 2;
      }

      console.log('type:', type);
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "home.index.userworkrentlist",
          m: "monai_market",
          uid: app.globalData.getuid(),
          type: type,
          leftid: that.leftid++
        },
        cachetime: "0",
        success: function (a) {
          console.log('自己列表信息返回：', a.data);
          that.setData({
            listInfo: that.listInfo.concat(a.data.data)
          });
        }
      });
    },
    //获取找工作或租赁列表信息
    getWRlist: function () {
      var that = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "home.index.workrentList",
          m: "monai_market",
          type: that.wh,
          leftid: that.leftid++
        },
        cachetime: "0",
        success: function (a) {
          console.log('列表信息返回：', a.data);
          that.setData({
            listInfo: that.listInfo.concat(a.data.data)
          });
        }
      });
    },
    //点击职位详情按钮
    click_toDet: function (e) {
      var that = this;
      var id = e.currentTarget.dataset.id;
      e.curre;
      wx.navigateTo({
        url: '/pagesA/jobDet/jobDet?wh=' + that.wh + '&id=' + id
      });
    },
    //点击发布按钮
    click_send: function () {
      var that = this;

      if (that.wh == 1 || that.wh == 3) {
        wx.navigateTo({
          url: '/pagesA/sJobLease/sJobLease?ty=1'
        });
      } else {
        wx.navigateTo({
          url: '/pagesA/sJobLease/sJobLease?ty=2'
        });
      }
    }
  }
};
</script>
<style>
@import "./joinUs.css";
</style>